package neca.tmazo.vista.vistaGUI;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
/**
 * 
 * @author neca
 * 
 * Esta clase se encarga de cargar todas las imagenes necesarias para el funcionamiento
 * del programa y de proporcionarselas al mismo cuando lo solicite.
 *
 */
public class ImageManager 
{
	public static final int IMAGE_LOGO_NECA = 0;
	public static final int IMAGE_LOGO_TMAZO = 1;
	public static final int IMAGE_LOADING=2;
	public static final int IMAGE_UP_VOTE = 3;
	public static final int IMAGE_DOWN_VOTE = 4;
	public static final int IMAGE_SONG=5;
	public static final int IMAGE_ALBUM=6;
	public static final int IMAGE_ALBUM_BIG=7;
	public static final int IMAGE_LOGO_TMAZO_LOGIN = 8;
	public static final int IMAGE_LOGO_TMAZO_FRAME_ICON = 9;
	public static final int IMAGE_LOGO_TMAZO_ALBUM_SONG = 10;
	public static final int IMAGE_ERROR_ICON = 11;
	public static final int IMAGE_INFO_ICON = 12;
	public static final int IMAGE_SONG_BIG = 13;
	
	public static final int NUMBER_IMAGES=14;
	
	private static boolean imagesLoaded=false;
	private static ImageIcon[] imageList;
	
	public static void loadImages()
	{
		if(imagesLoaded) return;
		imagesLoaded=true;
		
		imageList=new ImageIcon[NUMBER_IMAGES];
		try 
		{
			BufferedImage myPicture;
			myPicture = ImageIO.read(new File("img/logo_tmazo.png"));
			imageList[IMAGE_LOGO_TMAZO]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/logo_neca.png"));
			imageList[IMAGE_LOGO_NECA]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/song.png"));
			imageList[IMAGE_SONG]=new ImageIcon(myPicture);
			myPicture=ImageIO.read(new File("img/album.png"));
			imageList[IMAGE_ALBUM]=new ImageIcon(myPicture);
			Image myGIF=Toolkit.getDefaultToolkit().createImage("img/loading_gif.gif");
			imageList[IMAGE_LOADING]=new ImageIcon(myGIF);
			myPicture = ImageIO.read(new File("img/upvote.png"));
			imageList[IMAGE_UP_VOTE]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/downvote.png"));
			imageList[IMAGE_DOWN_VOTE]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/album_big.png"));
			imageList[IMAGE_ALBUM_BIG]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/logo_tmazo_login.png"));
			imageList[IMAGE_LOGO_TMAZO_LOGIN]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/logo_tmazo_frame_icon.png"));
			imageList[IMAGE_LOGO_TMAZO_FRAME_ICON]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/logo_tmazo_album-cancion.png"));
			imageList[IMAGE_LOGO_TMAZO_ALBUM_SONG]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/error_icon_small.png"));
			imageList[IMAGE_ERROR_ICON]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/info_icon_small.png"));
			imageList[IMAGE_INFO_ICON]=new ImageIcon(myPicture);
			myPicture = ImageIO.read(new File("img/song_big.png"));
			imageList[IMAGE_SONG_BIG]=new ImageIcon(myPicture);
		} catch (IOException e) {
			System.out.println("Error fatal: No se pueden cargar las imagenes.");
			System.out.println("Por favor, mande la siguiente informacion de error al servicio tecnico:");
			e.printStackTrace();
			System.exit(1);
		}
		
	}
	public static ImageIcon getImage(int imageID)
	{
		if(!imagesLoaded) loadImages();
		
		return imageList[imageID];
	}
}
